﻿namespace PlusPlusPaint.FileIO.AST
{
    interface INode
    {
        string ToPrettyString();
        void AddArg(string name, int i);
        void AddArg(string name, string str);
        void AddArg(string name, INode node);
        void AddArg(int i);
        void AddArg(string str);
        void AddArg(INode node);
        SerializedObject ToSerializedObject();
    }

    class INodeHelpers
    {
        public const int PrettyStringIndent = 2;

        /// <summary>
        /// Return a copy of the string with lines indented by the given amount.
        /// </summary>
        public static string Indent(string text, int amount)
        {
            string[] substrings = text.Split('\n');
            for (int i = 0; i < substrings.Length; ++i) // Remove trailing \r if present
                substrings[i] = substrings[i].TrimEnd();
            string result = "";
            foreach (string s in substrings)
                if (s.Trim() != "")
                    result += "".PadLeft(amount) + s + "\r\n";
            return result.TrimEnd();
        }
    }
}
